home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / src / linux-headers-2.6.20-15 / Makefile < prev   
Encoding:
Makefile  |  2007-04-12  |  49.3 KB  |  1,501 lines

  1. VERSION = 2
  2. PATCHLEVEL = 6
  3. SUBLEVEL = 20
  4. EXTRAVERSION = .3-ubuntu1
  5. NAME = Homicidal Dwarf Hamster
  6.  
  7. ifdef UBUNTUBUILD
  8. EXTRAVERSION =
  9. endif
  10.  
  11. # *DOCUMENTATION*
  12. # To see a list of typical targets execute "make help"
  13. # More info can be located in ./README
  14. # Comments in this file are targeted only to the developer, do not
  15. # expect to learn how to build the kernel reading this file.
  16.  
  17. # Do not:
  18. # o  use make's built-in rules and variables
  19. #    (this increases performance and avoid hard-to-debug behavour);
  20. # o  print "Entering directory ...";
  21. MAKEFLAGS += -rR --no-print-directory
  22.  
  23. # We are using a recursive build, so we need to do a little thinking
  24. # to get the ordering right.
  25. #
  26. # Most importantly: sub-Makefiles should only ever modify files in
  27. # their own directory. If in some directory we have a dependency on
  28. # a file in another dir (which doesn't happen often, but it's often
  29. # unavoidable when linking the built-in.o targets which finally
  30. # turn into vmlinux), we will call a sub make in that other dir, and
  31. # after that we are sure that everything which is in that other dir
  32. # is now up to date.
  33. #
  34. # The only cases where we need to modify files which have global
  35. # effects are thus separated out and done before the recursive
  36. # descending is started. They are now explicitly listed as the
  37. # prepare rule.
  38.  
  39. # To put more focus on warnings, be less verbose as default
  40. # Use 'make V=1' to see the full commands
  41.  
  42. ifdef V
  43.   ifeq ("$(origin V)", "command line")
  44.     KBUILD_VERBOSE = $(V)
  45.   endif
  46. endif
  47. ifndef KBUILD_VERBOSE
  48.   KBUILD_VERBOSE = 0
  49. endif
  50.  
  51. # Call a source code checker (by default, "sparse") as part of the
  52. # C compilation.
  53. #
  54. # Use 'make C=1' to enable checking of only re-compiled files.
  55. # Use 'make C=2' to enable checking of *all* source files, regardless
  56. # of whether they are re-compiled or not.
  57. #
  58. # See the file "Documentation/sparse.txt" for more details, including
  59. # where to get the "sparse" utility.
  60.  
  61. ifdef C
  62.   ifeq ("$(origin C)", "command line")
  63.     KBUILD_CHECKSRC = $(C)
  64.   endif
  65. endif
  66. ifndef KBUILD_CHECKSRC
  67.   KBUILD_CHECKSRC = 0
  68. endif
  69.  
  70. # Use make M=dir to specify directory of external module to build
  71. # Old syntax make ... SUBDIRS=$PWD is still supported
  72. # Setting the environment variable KBUILD_EXTMOD take precedence
  73. ifdef SUBDIRS
  74.   KBUILD_EXTMOD ?= $(SUBDIRS)
  75. endif
  76. ifdef M
  77.   ifeq ("$(origin M)", "command line")
  78.     KBUILD_EXTMOD := $(M)
  79.   endif
  80. endif
  81.  
  82.  
  83. # kbuild supports saving output files in a separate directory.
  84. # To locate output files in a separate directory two syntaxes are supported.
  85. # In both cases the working directory must be the root of the kernel src.
  86. # 1) O=
  87. # Use "make O=dir/to/store/output/files/"
  88. #
  89. # 2) Set KBUILD_OUTPUT
  90. # Set the environment variable KBUILD_OUTPUT to point to the directory
  91. # where the output files shall be placed.
  92. # export KBUILD_OUTPUT=dir/to/store/output/files/
  93. # make
  94. #
  95. # The O= assignment takes precedence over the KBUILD_OUTPUT environment
  96. # variable.
  97.  
  98.  
  99. # KBUILD_SRC is set on invocation of make in OBJ directory
  100. # KBUILD_SRC is not intended to be used by the regular user (for now)
  101. ifeq ($(KBUILD_SRC),)
  102.  
  103. # OK, Make called in directory where kernel src resides
  104. # Do we want to locate output files in a separate directory?
  105. ifdef O
  106.   ifeq ("$(origin O)", "command line")
  107.     KBUILD_OUTPUT := $(O)
  108.   endif
  109. endif
  110.  
  111. # That's our default target when none is given on the command line
  112. PHONY := _all
  113. _all:
  114.  
  115. ifneq ($(KBUILD_OUTPUT),)
  116. # Invoke a second make in the output directory, passing relevant variables
  117. # check that the output directory actually exists
  118. saved-output := $(KBUILD_OUTPUT)
  119. KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
  120. $(if $(KBUILD_OUTPUT),, \
  121.      $(error output directory "$(saved-output)" does not exist))
  122.  
  123. PHONY += $(MAKECMDGOALS)
  124.  
  125. $(filter-out _all,$(MAKECMDGOALS)) _all:
  126.     $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
  127.     KBUILD_SRC=$(CURDIR) \
  128.     KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile $@
  129.  
  130. # Leave processing to above invocation of make
  131. skip-makefile := 1
  132. endif # ifneq ($(KBUILD_OUTPUT),)
  133. endif # ifeq ($(KBUILD_SRC),)
  134.  
  135. # We process the rest of the Makefile if this is the final invocation of make
  136. ifeq ($(skip-makefile),)
  137.  
  138. # If building an external module we do not care about the all: rule
  139. # but instead _all depend on modules
  140. PHONY += all
  141. ifeq ($(KBUILD_EXTMOD),)
  142. _all: all
  143. else
  144. _all: modules
  145. endif
  146.  
  147. srctree        := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
  148. TOPDIR        := $(srctree)
  149. # FIXME - TOPDIR is obsolete, use srctree/objtree
  150. objtree        := $(CURDIR)
  151. src        := $(srctree)
  152. obj        := $(objtree)
  153.  
  154. VPATH        := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
  155.  
  156. export srctree objtree VPATH TOPDIR
  157.  
  158.  
  159. # SUBARCH tells the usermode build what the underlying arch is.  That is set
  160. # first, and if a usermode build is happening, the "ARCH=um" on the command
  161. # line overrides the setting of ARCH below.  If a native build is happening,
  162. # then ARCH is assigned, getting whatever value it gets normally, and 
  163. # SUBARCH is subsequently ignored.
  164.  
  165. SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
  166.                   -e s/arm.*/arm/ -e s/sa110/arm/ \
  167.                   -e s/s390x/s390/ -e s/parisc64/parisc/ \
  168.                   -e s/ppc.*/powerpc/ -e s/mips.*/mips/ )
  169.  
  170. # Cross compiling and selecting different set of gcc/bin-utils
  171. # ---------------------------------------------------------------------------
  172. #
  173. # When performing cross compilation for other architectures ARCH shall be set
  174. # to the target architecture. (See arch/* for the possibilities).
  175. # ARCH can be set during invocation of make:
  176. # make ARCH=ia64
  177. # Another way is to have ARCH set in the environment.
  178. # The default ARCH is the host where make is executed.
  179.  
  180. # CROSS_COMPILE specify the prefix used for all executables used
  181. # during compilation. Only gcc and related bin-utils executables
  182. # are prefixed with $(CROSS_COMPILE).
  183. # CROSS_COMPILE can be set on the command line
  184. # make CROSS_COMPILE=ia64-linux-
  185. # Alternatively CROSS_COMPILE can be set in the environment.
  186. # Default value for CROSS_COMPILE is not to prefix executables
  187. # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
  188.  
  189. ARCH        ?= $(SUBARCH)
  190. CROSS_COMPILE    ?=
  191.  
  192. # Architecture as present in compile.h
  193. UTS_MACHINE := $(ARCH)
  194.  
  195. KCONFIG_CONFIG    ?= .config
  196.  
  197. # SHELL used by kbuild
  198. CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
  199.       else if [ -x /bin/bash ]; then echo /bin/bash; \
  200.       else echo sh; fi ; fi)
  201.  
  202. HOSTCC       = gcc
  203. HOSTCXX      = g++
  204. HOSTCFLAGS   = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
  205. HOSTCXXFLAGS = -O2
  206.  
  207. # Decide whether to build built-in, modular, or both.
  208. # Normally, just do built-in.
  209.  
  210. KBUILD_MODULES :=
  211. KBUILD_BUILTIN := 1
  212.  
  213. #    If we have only "make modules", don't compile built-in objects.
  214. #    When we're building modules with modversions, we need to consider
  215. #    the built-in objects during the descend as well, in order to
  216. #    make sure the checksums are up to date before we record them.
  217.  
  218. ifeq ($(MAKECMDGOALS),modules)
  219.   KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
  220. endif
  221.  
  222. #    If we have "make <whatever> modules", compile modules
  223. #    in addition to whatever we do anyway.
  224. #    Just "make" or "make all" shall build modules as well
  225.  
  226. ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
  227.   KBUILD_MODULES := 1
  228. endif
  229.  
  230. ifeq ($(MAKECMDGOALS),)
  231.   KBUILD_MODULES := 1
  232. endif
  233.  
  234. export KBUILD_MODULES KBUILD_BUILTIN
  235. export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
  236.  
  237. # Beautify output
  238. # ---------------------------------------------------------------------------
  239. #
  240. # Normally, we echo the whole command before executing it. By making
  241. # that echo $($(quiet)$(cmd)), we now have the possibility to set
  242. # $(quiet) to choose other forms of output instead, e.g.
  243. #
  244. #         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
  245. #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
  246. #
  247. # If $(quiet) is empty, the whole command will be printed.
  248. # If it is set to "quiet_", only the short version will be printed. 
  249. # If it is set to "silent_", nothing will be printed at all, since
  250. # the variable $(silent_cmd_cc_o_c) doesn't exist.
  251. #
  252. # A simple variant is to prefix commands with $(Q) - that's useful
  253. # for commands that shall be hidden in non-verbose mode.
  254. #
  255. #    $(Q)ln $@ :<
  256. #
  257. # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
  258. # If KBUILD_VERBOSE equals 1 then the above command is displayed.
  259.  
  260. ifeq ($(KBUILD_VERBOSE),1)
  261.   quiet =
  262.   Q =
  263. else
  264.   quiet=quiet_
  265.   Q = @
  266. endif
  267.  
  268. # If the user is running make -s (silent mode), suppress echoing of
  269. # commands
  270.  
  271. ifneq ($(findstring s,$(MAKEFLAGS)),)
  272.   quiet=silent_
  273. endif
  274.  
  275. export quiet Q KBUILD_VERBOSE
  276.  
  277.  
  278. # Look for make include files relative to root of kernel src
  279. MAKEFLAGS += --include-dir=$(srctree)
  280.  
  281. # We need some generic definitions.
  282. include $(srctree)/scripts/Kbuild.include
  283.  
  284. # Make variables (CC, etc...)
  285.  
  286. AS        = $(CROSS_COMPILE)as
  287. LD        = $(CROSS_COMPILE)ld
  288. CC        = $(CROSS_COMPILE)gcc
  289. CPP        = $(CC) -E
  290. AR        = $(CROSS_COMPILE)ar
  291. NM        = $(CROSS_COMPILE)nm
  292. STRIP        = $(CROSS_COMPILE)strip
  293. OBJCOPY        = $(CROSS_COMPILE)objcopy
  294. OBJDUMP        = $(CROSS_COMPILE)objdump
  295. AWK        = awk
  296. GENKSYMS    = scripts/genksyms/genksyms
  297. DEPMOD        = /sbin/depmod
  298. KALLSYMS    = scripts/kallsyms
  299. PERL        = perl
  300. CHECK        = sparse
  301.  
  302. CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
  303. MODFLAGS    = -DMODULE
  304. CFLAGS_MODULE   = $(MODFLAGS)
  305. AFLAGS_MODULE   = $(MODFLAGS)
  306. LDFLAGS_MODULE  = -r
  307. CFLAGS_KERNEL    =
  308. AFLAGS_KERNEL    =
  309.  
  310.  
  311. # Use LINUXINCLUDE when you must reference the include/ directory.
  312. # Needed to be compatible with the O= option
  313. LINUXINCLUDE    := -Iinclude \
  314.                    $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
  315.            -include include/linux/autoconf.h
  316.  
  317. # UBUNTU: Include our third party driver stuff too
  318. LINUXINCLUDE    += -Iubuntu/include \
  319.            $(if $(KBUILD_SRC),-I$(srctree)/ubuntu/include)
  320.  
  321. CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
  322.  
  323. CFLAGS          := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
  324.                    -fno-strict-aliasing -fno-common
  325. AFLAGS          := -D__ASSEMBLY__
  326.  
  327. # Read KERNELRELEASE from include/config/kernel.release (if it exists)
  328. KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
  329. KERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
  330.  
  331. export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
  332. export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
  333. export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
  334. export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
  335.  
  336. export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
  337. export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
  338. export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
  339.  
  340. # When compiling out-of-tree modules, put MODVERDIR in the module
  341. # tree rather than in the kernel tree. The kernel tree might
  342. # even be read-only.
  343. export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
  344.  
  345. # Files to ignore in find ... statements
  346.  
  347. RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
  348. export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
  349.  
  350. # ===========================================================================
  351. # Rules shared between *config targets and build targets
  352.  
  353. # Basic helpers built in scripts/
  354. PHONY += scripts_basic
  355. scripts_basic:
  356.     $(Q)$(MAKE) $(build)=scripts/basic
  357.  
  358. # To avoid any implicit rule to kick in, define an empty command.
  359. scripts/basic/%: scripts_basic ;
  360.  
  361. PHONY += outputmakefile
  362. # outputmakefile generates a Makefile in the output directory, if using a
  363. # separate output directory. This allows convenient use of make in the
  364. # output directory.
  365. outputmakefile:
  366. ifneq ($(KBUILD_SRC),)
  367.     $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
  368.         $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
  369. endif
  370.  
  371. # To make sure we do not include .config for any of the *config targets
  372. # catch them early, and hand them over to scripts/kconfig/Makefile
  373. # It is allowed to specify more targets when calling make, including
  374. # mixing *config targets and build targets.
  375. # For example 'make oldconfig all'.
  376. # Detect when mixed targets is specified, and make a second invocation
  377. # of make so .config is not included in this case either (for *config).
  378.  
  379. no-dot-config-targets := clean mrproper distclean \
  380.              cscope TAGS tags help %docs check% \
  381.              include/linux/version.h headers_% \
  382.              kernelrelease kernelversion
  383.  
  384. config-targets := 0
  385. mixed-targets  := 0
  386. dot-config     := 1
  387.  
  388. ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
  389.     ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
  390.         dot-config := 0
  391.     endif
  392. endif
  393.  
  394. ifeq ($(KBUILD_EXTMOD),)
  395.         ifneq ($(filter config %config,$(MAKECMDGOALS)),)
  396.                 config-targets := 1
  397.                 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
  398.                         mixed-targets := 1
  399.                 endif
  400.         endif
  401. endif
  402.  
  403. ifeq ($(mixed-targets),1)
  404. # ===========================================================================
  405. # We're called with mixed targets (*config and build targets).
  406. # Handle them one by one.
  407.  
  408. %:: FORCE
  409.     $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
  410.  
  411. else
  412. ifeq ($(config-targets),1)
  413. # ===========================================================================
  414. # *config targets only - make sure prerequisites are updated, and descend
  415. # in scripts/kconfig to make the *config target
  416.  
  417. # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
  418. # KBUILD_DEFCONFIG may point out an alternative default configuration
  419. # used for 'make defconfig'
  420. include $(srctree)/arch/$(ARCH)/Makefile
  421. export KBUILD_DEFCONFIG
  422.  
  423. config %config: scripts_basic outputmakefile FORCE
  424.     $(Q)mkdir -p include/linux include/config
  425.     $(Q)$(MAKE) $(build)=scripts/kconfig $@
  426.  
  427. else
  428. # ===========================================================================
  429. # Build targets only - this includes vmlinux, arch specific targets, clean
  430. # targets and others. In general all targets except *config targets.
  431.  
  432. ifeq ($(KBUILD_EXTMOD),)
  433. # Additional helpers built in scripts/
  434. # Carefully list dependencies so we do not try to build scripts twice
  435. # in parallel
  436. PHONY += scripts
  437. scripts: scripts_basic include/config/auto.conf
  438.     $(Q)$(MAKE) $(build)=$(@)
  439.  
  440. # Objects we will link into vmlinux / subdirs we need to visit
  441. init-y        := init/
  442. drivers-y    := drivers/ sound/ ubuntu/
  443. net-y        := net/
  444. libs-y        := lib/
  445. core-y        := usr/
  446. endif # KBUILD_EXTMOD
  447.  
  448. ifeq ($(dot-config),1)
  449. # Read in config
  450. -include include/config/auto.conf
  451.  
  452. ifeq ($(KBUILD_EXTMOD),)
  453. # Read in dependencies to all Kconfig* files, make sure to run
  454. # oldconfig if changes are detected.
  455. -include include/config/auto.conf.cmd
  456.  
  457. # To avoid any implicit rule to kick in, define an empty command
  458. $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
  459.  
  460. # If .config is newer than include/config/auto.conf, someone tinkered
  461. # with it and forgot to run make oldconfig.
  462. # if auto.conf.cmd is missing then we are probably in a cleaned tree so
  463. # we execute the config step to be sure to catch updated Kconfig files
  464. include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
  465.     $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
  466. else
  467. # external modules needs include/linux/autoconf.h and include/config/auto.conf
  468. # but do not care if they are up-to-date. Use auto.conf to trigger the test
  469. PHONY += include/config/auto.conf
  470.  
  471. include/config/auto.conf:
  472.     $(Q)test -e include/linux/autoconf.h -a -e $@ || (        \
  473.     echo;                                \
  474.     echo "  ERROR: Kernel configuration is invalid.";        \
  475.     echo "         include/linux/autoconf.h or $@ are missing.";    \
  476.     echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";    \
  477.     echo;                                \
  478.     /bin/false)
  479.  
  480. endif # KBUILD_EXTMOD
  481.  
  482. else
  483. # Dummy target needed, because used as prerequisite
  484. include/config/auto.conf: ;
  485. endif # $(dot-config)
  486.  
  487. # The all: target is the default when no target is given on the
  488. # command line.
  489. # This allow a user to issue only 'make' to build a kernel including modules
  490. # Defaults vmlinux but it is usually overridden in the arch makefile
  491. all: vmlinux
  492.  
  493. ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
  494. CFLAGS        += -Os
  495. else
  496. CFLAGS        += -O2
  497. endif
  498.  
  499. include $(srctree)/arch/$(ARCH)/Makefile
  500.  
  501. ifdef CONFIG_FRAME_POINTER
  502. CFLAGS        += -fno-omit-frame-pointer $(call cc-option,-fno-optimize-sibling-calls,)
  503. else
  504. CFLAGS        += -fomit-frame-pointer
  505. endif
  506.  
  507. ifdef CONFIG_DEBUG_INFO
  508. CFLAGS        += -g
  509. endif
  510.  
  511. # Force gcc to behave correct even for buggy distributions
  512. CFLAGS          += $(call cc-option, -fno-stack-protector)
  513.  
  514. # arch Makefile may override CC so keep this after arch Makefile is included
  515. NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
  516. CHECKFLAGS     += $(NOSTDINC_FLAGS)
  517.  
  518. # warn about C99 declaration after statement
  519. CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
  520.  
  521. # disable pointer signed / unsigned warnings in gcc 4.0
  522. CFLAGS += $(call cc-option,-Wno-pointer-sign,)
  523.  
  524. # Default kernel image to build when no specific target is given.
  525. # KBUILD_IMAGE may be overruled on the command line or
  526. # set in the environment
  527. # Also any assignments in arch/$(ARCH)/Makefile take precedence over
  528. # this default value
  529. export KBUILD_IMAGE ?= vmlinux
  530.  
  531. #
  532. # INSTALL_PATH specifies where to place the updated kernel and system map
  533. # images. Default is /boot, but you can set it to other values
  534. export    INSTALL_PATH ?= /boot
  535.  
  536. #
  537. # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
  538. # relocations required by build roots.  This is not defined in the
  539. # makefile but the argument can be passed to make if needed.
  540. #
  541.  
  542. MODLIB    = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
  543. export MODLIB
  544.  
  545. #
  546. #  INSTALL_MOD_STRIP, if defined, will cause modules to be
  547. #  stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
  548. #  the default option --strip-debug will be used.  Otherwise,
  549. #  INSTALL_MOD_STRIP will used as the options to the strip command.
  550.  
  551. ifdef INSTALL_MOD_STRIP
  552. ifeq ($(INSTALL_MOD_STRIP),1)
  553. mod_strip_cmd = $(STRIP) --strip-debug
  554. else
  555. mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
  556. endif # INSTALL_MOD_STRIP=1
  557. else
  558. mod_strip_cmd = true
  559. endif # INSTALL_MOD_STRIP
  560. export mod_strip_cmd
  561.  
  562.  
  563. ifeq ($(KBUILD_EXTMOD),)
  564. core-y        += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
  565.  
  566. vmlinux-dirs    := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
  567.              $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
  568.              $(net-y) $(net-m) $(libs-y) $(libs-m)))
  569.  
  570. vmlinux-alldirs    := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
  571.              $(init-n) $(init-) \
  572.              $(core-n) $(core-) $(drivers-n) $(drivers-) \
  573.              $(net-n)  $(net-)  $(libs-n)    $(libs-))))
  574.  
  575. init-y        := $(patsubst %/, %/built-in.o, $(init-y))
  576. core-y        := $(patsubst %/, %/built-in.o, $(core-y))
  577. drivers-y    := $(patsubst %/, %/built-in.o, $(drivers-y))
  578. net-y        := $(patsubst %/, %/built-in.o, $(net-y))
  579. libs-y1        := $(patsubst %/, %/lib.a, $(libs-y))
  580. libs-y2        := $(patsubst %/, %/built-in.o, $(libs-y))
  581. libs-y        := $(libs-y1) $(libs-y2)
  582.  
  583. # Build vmlinux
  584. # ---------------------------------------------------------------------------
  585. # vmlinux is built from the objects selected by $(vmlinux-init) and
  586. # $(vmlinux-main). Most are built-in.o files from top-level directories
  587. # in the kernel tree, others are specified in arch/$(ARCH)Makefile.
  588. # Ordering when linking is important, and $(vmlinux-init) must be first.
  589. #
  590. # vmlinux
  591. #   ^
  592. #   |
  593. #   +-< $(vmlinux-init)
  594. #   |   +--< init/version.o + more
  595. #   |
  596. #   +--< $(vmlinux-main)
  597. #   |    +--< driver/built-in.o mm/built-in.o + more
  598. #   |
  599. #   +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
  600. #
  601. # vmlinux version (uname -v) cannot be updated during normal
  602. # descending-into-subdirs phase since we do not yet know if we need to
  603. # update vmlinux.
  604. # Therefore this step is delayed until just before final link of vmlinux -
  605. # except in the kallsyms case where it is done just before adding the
  606. # symbols to the kernel.
  607. #
  608. # System.map is generated to document addresses of all kernel symbols
  609.  
  610. vmlinux-init := $(head-y) $(init-y)
  611. vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
  612. vmlinux-all  := $(vmlinux-init) $(vmlinux-main)
  613. vmlinux-lds  := arch/$(ARCH)/kernel/vmlinux.lds
  614.  
  615. # Rule to link vmlinux - also used during CONFIG_KALLSYMS
  616. # May be overridden by arch/$(ARCH)/Makefile
  617. quiet_cmd_vmlinux__ ?= LD      $@
  618.       cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
  619.       -T $(vmlinux-lds) $(vmlinux-init)                          \
  620.       --start-group $(vmlinux-main) --end-group                  \
  621.       $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
  622.  
  623. # Generate new vmlinux version
  624. quiet_cmd_vmlinux_version = GEN     .version
  625.       cmd_vmlinux_version = set -e;                     \
  626.     if [ ! -r .version ]; then            \
  627.       rm -f .version;                \
  628.       echo 1 >.version;                \
  629.     else                        \
  630.       mv .version .old_version;            \
  631.       expr 0$$(cat .old_version) + 1 >.version;    \
  632.     fi;                        \
  633.     $(MAKE) $(build)=init
  634.  
  635. # Generate System.map
  636. quiet_cmd_sysmap = SYSMAP
  637.       cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
  638.  
  639. # Link of vmlinux
  640. # If CONFIG_KALLSYMS is set .version is already updated
  641. # Generate System.map and verify that the content is consistent
  642. # Use + in front of the vmlinux_version rule to silent warning with make -j2
  643. # First command is ':' to allow us to use + in front of the rule
  644. define rule_vmlinux__
  645.     :
  646.     $(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version))
  647.  
  648.     $(call cmd,vmlinux__)
  649.     $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
  650.  
  651.     $(Q)$(if $($(quiet)cmd_sysmap),                                      \
  652.       echo '  $($(quiet)cmd_sysmap)  System.map' &&)                     \
  653.     $(cmd_sysmap) $@ System.map;                                         \
  654.     if [ $$? -ne 0 ]; then                                               \
  655.         rm -f $@;                                                    \
  656.         /bin/false;                                                  \
  657.     fi;
  658.     $(verify_kallsyms)
  659. endef
  660.  
  661.  
  662. ifdef CONFIG_KALLSYMS
  663. # Generate section listing all symbols and add it into vmlinux $(kallsyms.o)
  664. # It's a three stage process:
  665. # o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
  666. #   empty
  667. #   Running kallsyms on that gives us .tmp_kallsyms1.o with
  668. #   the right size - vmlinux version (uname -v) is updated during this step
  669. # o .tmp_vmlinux2 now has a __kallsyms section of the right size,
  670. #   but due to the added section, some addresses have shifted.
  671. #   From here, we generate a correct .tmp_kallsyms2.o
  672. # o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
  673. # o Verify that the System.map from vmlinux matches the map from
  674. #   .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
  675. # o If CONFIG_KALLSYMS_EXTRA_PASS is set, do an extra pass using
  676. #   .tmp_vmlinux3 and .tmp_kallsyms3.o.  This is only meant as a
  677. #   temporary bypass to allow the kernel to be built while the
  678. #   maintainers work out what went wrong with kallsyms.
  679.  
  680. ifdef CONFIG_KALLSYMS_EXTRA_PASS
  681. last_kallsyms := 3
  682. else
  683. last_kallsyms := 2
  684. endif
  685.  
  686. kallsyms.o := .tmp_kallsyms$(last_kallsyms).o
  687.  
  688. define verify_kallsyms
  689.     $(Q)$(if $($(quiet)cmd_sysmap),                                      \
  690.       echo '  $($(quiet)cmd_sysmap)  .tmp_System.map' &&)                \
  691.       $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
  692.     $(Q)cmp -s System.map .tmp_System.map ||                             \
  693.         (echo Inconsistent kallsyms data;                            \
  694.          echo Try setting CONFIG_KALLSYMS_EXTRA_PASS;                \
  695.          rm .tmp_kallsyms* ; /bin/false )
  696. endef
  697.  
  698. # Update vmlinux version before link
  699. # Use + in front of this rule to silent warning about make -j1
  700. # First command is ':' to allow us to use + in front of this rule
  701. cmd_ksym_ld = $(cmd_vmlinux__)
  702. define rule_ksym_ld
  703.     : 
  704.     +$(call cmd,vmlinux_version)
  705.     $(call cmd,vmlinux__)
  706.     $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
  707. endef
  708.  
  709. # Generate .S file with all kernel symbols
  710. quiet_cmd_kallsyms = KSYM    $@
  711.       cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) \
  712.                      $(if $(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
  713.  
  714. .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o: %.o: %.S scripts FORCE
  715.     $(call if_changed_dep,as_o_S)
  716.  
  717. .tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS)
  718.     $(call cmd,kallsyms)
  719.  
  720. # .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version
  721. .tmp_vmlinux1: $(vmlinux-lds) $(vmlinux-all) FORCE
  722.     $(call if_changed_rule,ksym_ld)
  723.  
  724. .tmp_vmlinux2: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms1.o FORCE
  725.     $(call if_changed,vmlinux__)
  726.  
  727. .tmp_vmlinux3: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms2.o FORCE
  728.     $(call if_changed,vmlinux__)
  729.  
  730. # Needs to visit scripts/ before $(KALLSYMS) can be used.
  731. $(KALLSYMS): scripts ;
  732.  
  733. # Generate some data for debugging strange kallsyms problems
  734. debug_kallsyms: .tmp_map$(last_kallsyms)
  735.  
  736. .tmp_map%: .tmp_vmlinux% FORCE
  737.     ($(OBJDUMP) -h $< | $(AWK) '/^ +[0-9]/{print $$4 " 0 " $$2}'; $(NM) $<) | sort > $@
  738.  
  739. .tmp_map3: .tmp_map2
  740.  
  741. .tmp_map2: .tmp_map1
  742.  
  743. endif # ifdef CONFIG_KALLSYMS
  744.  
  745. # vmlinux image - including updated kernel symbols
  746. vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) $(kallsyms.o) FORCE
  747. ifdef CONFIG_HEADERS_CHECK
  748.     $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
  749. endif
  750.     $(call if_changed_rule,vmlinux__)
  751.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@
  752.     $(Q)rm -f .old_version
  753.  
  754. # The actual objects are generated when descending, 
  755. # make sure no implicit rule kicks in
  756. $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
  757.  
  758. # Handle descending into subdirectories listed in $(vmlinux-dirs)
  759. # Preset locale variables to speed up the build process. Limit locale
  760. # tweaks to this spot to avoid wrong language settings when running
  761. # make menuconfig etc.
  762. # Error messages still appears in the original language
  763.  
  764. PHONY += $(vmlinux-dirs)
  765. $(vmlinux-dirs): prepare scripts
  766.     $(Q)$(MAKE) $(build)=$@
  767.  
  768. # Build the kernel release string
  769. #
  770. # The KERNELRELEASE value built here is stored in the file
  771. # include/config/kernel.release, and is used when executing several
  772. # make targets, such as "make install" or "make modules_install."
  773. #
  774. # The eventual kernel release string consists of the following fields,
  775. # shown in a hierarchical format to show how smaller parts are concatenated
  776. # to form the larger and final value, with values coming from places like
  777. # the Makefile, kernel config options, make command line options and/or
  778. # SCM tag information.
  779. #
  780. #    $(KERNELVERSION)
  781. #      $(VERSION)            eg, 2
  782. #      $(PATCHLEVEL)            eg, 6
  783. #      $(SUBLEVEL)            eg, 18
  784. #      $(EXTRAVERSION)        eg, -rc6
  785. #    $(localver-full)
  786. #      $(localver)
  787. #        localversion*        (all localversion* files)
  788. #        $(CONFIG_LOCALVERSION)    (from kernel config setting)
  789. #      $(localver-auto)        (only if CONFIG_LOCALVERSION_AUTO is set)
  790. #        ./scripts/setlocalversion    (SCM tag, if one exists)
  791. #        $(LOCALVERSION)        (from make command line if provided)
  792. #
  793. #  Note how the final $(localver-auto) string is included *only* if the
  794. # kernel config option CONFIG_LOCALVERSION_AUTO is selected.  Also, at the
  795. # moment, only git is supported but other SCMs can edit the script
  796. # scripts/setlocalversion and add the appropriate checks as needed.
  797.  
  798. nullstring :=
  799. space      := $(nullstring) # end of line
  800.  
  801. ___localver = $(objtree)/localversion* $(srctree)/localversion*
  802. __localver  = $(sort $(wildcard $(___localver)))
  803. # skip backup files (containing '~')
  804. _localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f)))
  805.  
  806. localver = $(subst $(space),, \
  807.        $(shell cat /dev/null $(_localver)) \
  808.        $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
  809.  
  810. # If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
  811. # and if the SCM is know a tag from the SCM is appended.
  812. # The appended tag is determined by the SCM used.
  813. #
  814. # Currently, only git is supported.
  815. # Other SCMs can edit scripts/setlocalversion and add the appropriate
  816. # checks as needed.
  817. ifdef CONFIG_LOCALVERSION_AUTO
  818.     _localver-auto = $(shell $(CONFIG_SHELL) \
  819.                       $(srctree)/scripts/setlocalversion $(srctree))
  820.     localver-auto  = $(LOCALVERSION)$(_localver-auto)
  821. endif
  822.  
  823. localver-full = $(localver)$(localver-auto)
  824.  
  825. # Store (new) KERNELRELASE string in include/config/kernel.release
  826. kernelrelease = $(KERNELVERSION)$(localver-full)
  827. include/config/kernel.release: include/config/auto.conf FORCE
  828.     $(Q)rm -f $@
  829.     $(Q)echo $(kernelrelease) > $@
  830.  
  831.  
  832. # Things we need to do before we recursively start building the kernel
  833. # or the modules are listed in "prepare".
  834. # A multi level approach is used. prepareN is processed before prepareN-1.
  835. # archprepare is used in arch Makefiles and when processed asm symlink,
  836. # version.h and scripts_basic is processed / created.
  837.  
  838. # Listed in dependency order
  839. PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
  840.  
  841. # prepare-all is deprecated, use prepare as valid replacement
  842. PHONY += prepare-all
  843.  
  844. # prepare3 is used to check if we are building in a separate output directory,
  845. # and if so do:
  846. # 1) Check that make has not been executed in the kernel src $(srctree)
  847. # 2) Create the include2 directory, used for the second asm symlink
  848. prepare3: include/config/kernel.release
  849. ifneq ($(KBUILD_SRC),)
  850.     @echo '  Using $(srctree) as source for kernel'
  851.     $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
  852.         echo "  $(srctree) is not clean, please run 'make mrproper'";\
  853.         echo "  in the '$(srctree)' directory.";\
  854.         /bin/false; \
  855.     fi;
  856.     $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
  857.     $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
  858. endif
  859.  
  860. # prepare2 creates a makefile if using a separate output directory
  861. prepare2: prepare3 outputmakefile
  862.  
  863. prepare1: prepare2 include/linux/version.h include/linux/utsrelease.h \
  864.                    include/asm include/config/auto.conf
  865. ifneq ($(KBUILD_MODULES),)
  866.     $(Q)mkdir -p $(MODVERDIR)
  867.     $(Q)rm -f $(MODVERDIR)/*
  868. endif
  869.  
  870. archprepare: prepare1 scripts_basic
  871.  
  872. prepare0: archprepare FORCE
  873.     $(Q)$(MAKE) $(build)=.
  874.  
  875. # All the preparing..
  876. prepare prepare-all: prepare0
  877.  
  878. # Leave this as default for preprocessing vmlinux.lds.S, which is now
  879. # done in arch/$(ARCH)/kernel/Makefile
  880.  
  881. export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
  882.  
  883. # FIXME: The asm symlink changes when $(ARCH) changes. That's
  884. # hard to detect, but I suppose "make mrproper" is a good idea
  885. # before switching between archs anyway.
  886.  
  887. include/asm:
  888.     @echo '  SYMLINK $@ -> include/asm-$(ARCH)'
  889.     $(Q)if [ ! -d include ]; then mkdir -p include; fi;
  890.     @ln -fsn asm-$(ARCH) $@
  891.  
  892. # Generate some files
  893. # ---------------------------------------------------------------------------
  894.  
  895. # KERNELRELEASE can change from a few different places, meaning version.h
  896. # needs to be updated, so this check is forced on all builds
  897.  
  898. uts_len := 64
  899. define filechk_utsrelease.h
  900.     if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
  901.       echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    \
  902.       exit 1;                                                         \
  903.     fi;                                                               \
  904.     (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
  905. endef
  906.  
  907. define filechk_version.h
  908.     (echo \#define LINUX_VERSION_CODE $(shell                             \
  909.     expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL));     \
  910.     echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
  911. endef
  912.  
  913. include/linux/version.h: $(srctree)/Makefile FORCE
  914.     $(call filechk,version.h)
  915.  
  916. include/linux/utsrelease.h: include/config/kernel.release FORCE
  917.     $(call filechk,utsrelease.h)
  918.  
  919. # ---------------------------------------------------------------------------
  920.  
  921. PHONY += depend dep
  922. depend dep:
  923.     @echo '*** Warning: make $@ is unnecessary now.'
  924.  
  925. # ---------------------------------------------------------------------------
  926. # Kernel headers
  927. INSTALL_HDR_PATH=$(objtree)/usr
  928. export INSTALL_HDR_PATH
  929.  
  930. HDRARCHES=$(filter-out generic,$(patsubst $(srctree)/include/asm-%/Kbuild,%,$(wildcard $(srctree)/include/asm-*/Kbuild)))
  931.  
  932. PHONY += headers_install_all
  933. headers_install_all: include/linux/version.h scripts_basic FORCE
  934.     $(Q)$(MAKE) $(build)=scripts scripts/unifdef
  935.     $(Q)for arch in $(HDRARCHES); do \
  936.      $(MAKE) ARCH=$$arch -f $(srctree)/scripts/Makefile.headersinst obj=include BIASMDIR=-bi-$$arch ;\
  937.      done
  938.  
  939. PHONY += headers_install
  940. headers_install: include/linux/version.h scripts_basic FORCE
  941.     @if [ ! -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \
  942.       echo '*** Error: Headers not exportable for this architecture ($(ARCH))'; \
  943.       exit 1 ; fi
  944.     $(Q)$(MAKE) $(build)=scripts scripts/unifdef
  945.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include
  946.  
  947. PHONY += headers_check
  948. headers_check: headers_install
  949.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include HDRCHECK=1
  950.  
  951. # ---------------------------------------------------------------------------
  952. # Modules
  953.  
  954. ifdef CONFIG_MODULES
  955.  
  956. # By default, build modules as well
  957.  
  958. all: modules
  959.  
  960. #    Build modules
  961.  
  962. PHONY += modules
  963. modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
  964.     @echo '  Building modules, stage 2.';
  965.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  966.  
  967.  
  968. # Target to prepare building external modules
  969. PHONY += modules_prepare
  970. modules_prepare: prepare scripts
  971.  
  972. # Target to install modules
  973. PHONY += modules_install
  974. modules_install: _modinst_ _modinst_post
  975.  
  976. PHONY += _modinst_
  977. _modinst_:
  978.     @if [ -z "`$(DEPMOD) -V 2>/dev/null | grep module-init-tools`" ]; then \
  979.         echo "Warning: you may need to install module-init-tools"; \
  980.         echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
  981.         sleep 1; \
  982.     fi
  983.     @rm -rf $(MODLIB)/kernel
  984.     @rm -f $(MODLIB)/source
  985.     @mkdir -p $(MODLIB)/kernel
  986.     @ln -s $(srctree) $(MODLIB)/source
  987.     @if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
  988.         rm -f $(MODLIB)/build ; \
  989.         ln -s $(objtree) $(MODLIB)/build ; \
  990.     fi
  991.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
  992.  
  993. # If System.map exists, run depmod.  This deliberately does not have a
  994. # dependency on System.map since that would run the dependency tree on
  995. # vmlinux.  This depmod is only for convenience to give the initial
  996. # boot a modules.dep even before / is mounted read-write.  However the
  997. # boot script depmod is the master version.
  998. ifeq "$(strip $(INSTALL_MOD_PATH))" ""
  999. depmod_opts    :=
  1000. else
  1001. depmod_opts    := -b $(INSTALL_MOD_PATH) -r
  1002. endif
  1003. PHONY += _modinst_post
  1004. _modinst_post: _modinst_
  1005.     if [ -r System.map -a -x $(DEPMOD) ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
  1006.  
  1007. else # CONFIG_MODULES
  1008.  
  1009. # Modules not configured
  1010. # ---------------------------------------------------------------------------
  1011.  
  1012. modules modules_install: FORCE
  1013.     @echo
  1014.     @echo "The present kernel configuration has modules disabled."
  1015.     @echo "Type 'make config' and enable loadable module support."
  1016.     @echo "Then build a kernel with module support enabled."
  1017.     @echo
  1018.     @exit 1
  1019.  
  1020. endif # CONFIG_MODULES
  1021.  
  1022. ###
  1023. # Cleaning is done on three levels.
  1024. # make clean     Delete most generated files
  1025. #                Leave enough to build external modules
  1026. # make mrproper  Delete the current configuration, and all generated files
  1027. # make distclean Remove editor backup files, patch leftover files and the like
  1028.  
  1029. # Directories & files removed with 'make clean'
  1030. CLEAN_DIRS  += $(MODVERDIR)
  1031. CLEAN_FILES +=    vmlinux System.map \
  1032.                 .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
  1033.  
  1034. # Directories & files removed with 'make mrproper'
  1035. MRPROPER_DIRS  += include/config include2 usr/include
  1036. MRPROPER_FILES += .config .config.old include/asm .version .old_version \
  1037.                   include/linux/autoconf.h include/linux/version.h      \
  1038.                   include/linux/utsrelease.h                            \
  1039.           Module.symvers tags TAGS cscope*
  1040.  
  1041. # clean - Delete most, but leave enough to build external modules
  1042. #
  1043. clean: rm-dirs  := $(CLEAN_DIRS)
  1044. clean: rm-files := $(CLEAN_FILES)
  1045. clean-dirs      := $(addprefix _clean_,$(srctree) $(vmlinux-alldirs))
  1046.  
  1047. PHONY += $(clean-dirs) clean archclean
  1048. $(clean-dirs):
  1049.     $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
  1050.  
  1051. clean: archclean $(clean-dirs)
  1052.     $(call cmd,rmdirs)
  1053.     $(call cmd,rmfiles)
  1054.     @find . $(RCS_FIND_IGNORE) \
  1055.         \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
  1056.         -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
  1057.         -o -name '*.symtypes' \) \
  1058.         -type f -print | xargs rm -f
  1059.  
  1060. # mrproper - Delete all generated files, including .config
  1061. #
  1062. mrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
  1063. mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
  1064. mrproper-dirs      := $(addprefix _mrproper_,Documentation/DocBook scripts)
  1065.  
  1066. PHONY += $(mrproper-dirs) mrproper archmrproper
  1067. $(mrproper-dirs):
  1068.     $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
  1069.  
  1070. mrproper: clean archmrproper $(mrproper-dirs)
  1071.     $(call cmd,rmdirs)
  1072.     $(call cmd,rmfiles)
  1073.  
  1074. # distclean
  1075. #
  1076. PHONY += distclean
  1077.  
  1078. distclean: mrproper
  1079.     @find $(srctree) $(RCS_FIND_IGNORE) \
  1080.         \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
  1081.         -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
  1082.         -o -name '.*.rej' -o -size 0 \
  1083.         -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
  1084.         -type f -print | xargs rm -f
  1085.  
  1086.  
  1087. # Packaging of the kernel to various formats
  1088. # ---------------------------------------------------------------------------
  1089. # rpm target kept for backward compatibility
  1090. package-dir    := $(srctree)/scripts/package
  1091.  
  1092. %pkg: include/config/kernel.release FORCE
  1093.     $(Q)$(MAKE) $(build)=$(package-dir) $@
  1094. rpm: include/config/kernel.release FORCE
  1095.     $(Q)$(MAKE) $(build)=$(package-dir) $@
  1096.  
  1097.  
  1098. # Brief documentation of the typical targets used
  1099. # ---------------------------------------------------------------------------
  1100.  
  1101. boards := $(wildcard $(srctree)/arch/$(ARCH)/configs/*_defconfig)
  1102. boards := $(notdir $(boards))
  1103.  
  1104. help:
  1105.     @echo  'Cleaning targets:'
  1106.     @echo  '  clean          - Remove most generated files but keep the config and'
  1107.     @echo  '                    enough build support to build external modules'
  1108.     @echo  '  mrproper      - Remove all generated files + config + various backup files'
  1109.     @echo  '  distclean      - mrproper + remove editor backup and patch files'
  1110.     @echo  ''
  1111.     @echo  'Configuration targets:'
  1112.     @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
  1113.     @echo  ''
  1114.     @echo  'Other generic targets:'
  1115.     @echo  '  all          - Build all targets marked with [*]'
  1116.     @echo  '* vmlinux      - Build the bare kernel'
  1117.     @echo  '* modules      - Build all modules'
  1118.     @echo  '  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
  1119.     @echo  '  dir/            - Build all files in dir and below'
  1120.     @echo  '  dir/file.[ois]  - Build specified target only'
  1121.     @echo  '  dir/file.ko     - Build module including final link'
  1122.     @echo  '  rpm          - Build a kernel as an RPM package'
  1123.     @echo  '  tags/TAGS      - Generate tags file for editors'
  1124.     @echo  '  cscope      - Generate cscope index'
  1125.     @echo  '  kernelrelease      - Output the release version string'
  1126.     @echo  '  kernelversion      - Output the version stored in Makefile'
  1127.     @if [ -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \
  1128.      echo  '  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
  1129.      echo  '                    (default: $(INSTALL_HDR_PATH))'; \
  1130.      fi
  1131.     @echo  ''
  1132.     @echo  'Static analysers'
  1133.     @echo  '  checkstack      - Generate a list of stack hogs'
  1134.     @echo  '  namespacecheck  - Name space analysis on compiled kernel'
  1135.     @if [ -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \
  1136.      echo  '  headers_check   - Sanity check on exported headers'; \
  1137.      fi
  1138.     @echo  ''
  1139.     @echo  'Kernel packaging:'
  1140.     @$(MAKE) $(build)=$(package-dir) help
  1141.     @echo  ''
  1142.     @echo  'Documentation targets:'
  1143.     @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
  1144.     @echo  ''
  1145.     @echo  'Architecture specific targets ($(ARCH)):'
  1146.     @$(if $(archhelp),$(archhelp),\
  1147.         echo '  No architecture specific help defined for $(ARCH)')
  1148.     @echo  ''
  1149.     @$(if $(boards), \
  1150.         $(foreach b, $(boards), \
  1151.         printf "  %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
  1152.         echo '')
  1153.  
  1154.     @echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
  1155.     @echo  '  make V=2   [targets] 2 => give reason for rebuild of target'
  1156.     @echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
  1157.     @echo  '  make C=1   [targets] Check all c source with $$CHECK (sparse by default)'
  1158.     @echo  '  make C=2   [targets] Force check of all c source with $$CHECK'
  1159.     @echo  ''
  1160.     @echo  'Execute "make" or "make all" to build all targets marked with [*] '
  1161.     @echo  'For further info see the ./README file'
  1162.  
  1163.  
  1164. # Documentation targets
  1165. # ---------------------------------------------------------------------------
  1166. %docs: scripts_basic FORCE
  1167.     $(Q)$(MAKE) $(build)=Documentation/DocBook $@
  1168.  
  1169. else # KBUILD_EXTMOD
  1170.  
  1171. ###
  1172. # External module support.
  1173. # When building external modules the kernel used as basis is considered
  1174. # read-only, and no consistency checks are made and the make
  1175. # system is not used on the basis kernel. If updates are required
  1176. # in the basis kernel ordinary make commands (without M=...) must
  1177. # be used.
  1178. #
  1179. # The following are the only valid targets when building external
  1180. # modules.
  1181. # make M=dir clean     Delete all automatically generated files
  1182. # make M=dir modules   Make all modules in specified dir
  1183. # make M=dir           Same as 'make M=dir modules'
  1184. # make M=dir modules_install
  1185. #                      Install the modules built in the module directory
  1186. #                      Assumes install directory is already created
  1187.  
  1188. # We are always building modules
  1189. KBUILD_MODULES := 1
  1190. PHONY += crmodverdir
  1191. crmodverdir:
  1192.     $(Q)mkdir -p $(MODVERDIR)
  1193.     $(Q)rm -f $(MODVERDIR)/*
  1194.  
  1195. PHONY += $(objtree)/Module.symvers
  1196. $(objtree)/Module.symvers:
  1197.     @test -e $(objtree)/Module.symvers || ( \
  1198.     echo; \
  1199.     echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \
  1200.     echo "           is missing; modules will have no dependencies and modversions."; \
  1201.     echo )
  1202.  
  1203. module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
  1204. PHONY += $(module-dirs) modules
  1205. $(module-dirs): crmodverdir $(objtree)/Module.symvers
  1206.     $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
  1207.  
  1208. modules: $(module-dirs)
  1209.     @echo '  Building modules, stage 2.';
  1210.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  1211.  
  1212. PHONY += modules_install
  1213. modules_install: _emodinst_ _emodinst_post
  1214.  
  1215. install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
  1216. PHONY += _emodinst_
  1217. _emodinst_:
  1218.     $(Q)mkdir -p $(MODLIB)/$(install-dir)
  1219.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
  1220.  
  1221. # Run depmod only is we have System.map and depmod is executable
  1222. quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)
  1223.       cmd_depmod = if [ -r System.map -a -x $(DEPMOD) ]; then \
  1224.                       $(DEPMOD) -ae -F System.map             \
  1225.                       $(if $(strip $(INSTALL_MOD_PATH)),      \
  1226.               -b $(INSTALL_MOD_PATH) -r)              \
  1227.               $(KERNELRELEASE);                       \
  1228.                    fi
  1229.  
  1230. PHONY += _emodinst_post
  1231. _emodinst_post: _emodinst_
  1232.     $(call cmd,depmod)
  1233.  
  1234. clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
  1235.  
  1236. PHONY += $(clean-dirs) clean
  1237. $(clean-dirs):
  1238.     $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
  1239.  
  1240. clean:    rm-dirs := $(MODVERDIR)
  1241. clean: $(clean-dirs)
  1242.     $(call cmd,rmdirs)
  1243.     @find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
  1244.         \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
  1245.         -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
  1246.         -type f -print | xargs rm -f
  1247.  
  1248. help:
  1249.     @echo  '  Building external modules.'
  1250.     @echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
  1251.     @echo  ''
  1252.     @echo  '  modules         - default target, build the module(s)'
  1253.     @echo  '  modules_install - install the module'
  1254.     @echo  '  clean           - remove generated files in module directory only'
  1255.     @echo  ''
  1256.  
  1257. # Dummies...
  1258. PHONY += prepare scripts
  1259. prepare: ;
  1260. scripts: ;
  1261. endif # KBUILD_EXTMOD
  1262.  
  1263. # Generate tags for editors
  1264. # ---------------------------------------------------------------------------
  1265.  
  1266. #We want __srctree to totally vanish out when KBUILD_OUTPUT is not set
  1267. #(which is the most common case IMHO) to avoid unneeded clutter in the big tags file.
  1268. #Adding $(srctree) adds about 20M on i386 to the size of the output file!
  1269.  
  1270. ifeq ($(src),$(obj))
  1271. __srctree =
  1272. else
  1273. __srctree = $(srctree)/
  1274. endif
  1275.  
  1276. ifeq ($(ALLSOURCE_ARCHS),)
  1277. ifeq ($(ARCH),um)
  1278. ALLINCLUDE_ARCHS := $(ARCH) $(SUBARCH)
  1279. else
  1280. ALLINCLUDE_ARCHS := $(ARCH)
  1281. endif
  1282. else
  1283. #Allow user to specify only ALLSOURCE_PATHS on the command line, keeping existing behavour.
  1284. ALLINCLUDE_ARCHS := $(ALLSOURCE_ARCHS)
  1285. endif
  1286.  
  1287. ALLSOURCE_ARCHS := $(ARCH)
  1288.  
  1289. define find-sources
  1290.         ( find $(__srctree) $(RCS_FIND_IGNORE) \
  1291.            \( -name include -o -name arch \) -prune -o \
  1292.            -name $1 -print; \
  1293.       for ARCH in $(ALLSOURCE_ARCHS) ; do \
  1294.            find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \
  1295.                 -name $1 -print; \
  1296.       done ; \
  1297.       find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
  1298.            -name $1 -print; \
  1299.       find $(__srctree)include $(RCS_FIND_IGNORE) \
  1300.            \( -name config -o -name 'asm-*' \) -prune \
  1301.            -o -name $1 -print; \
  1302.       for ARCH in $(ALLINCLUDE_ARCHS) ; do \
  1303.            find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \
  1304.                 -name $1 -print; \
  1305.       done ; \
  1306.       find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
  1307.            -name $1 -print )
  1308. endef
  1309.  
  1310. define all-sources
  1311.     $(call find-sources,'*.[chS]')
  1312. endef
  1313. define all-kconfigs
  1314.     $(call find-sources,'Kconfig*')
  1315. endef
  1316. define all-defconfigs
  1317.     $(call find-sources,'defconfig')
  1318. endef
  1319.  
  1320. define xtags
  1321.     if $1 --version 2>&1 | grep -iq exuberant; then \
  1322.         $(all-sources) | xargs $1 -a \
  1323.         -I __initdata,__exitdata,__acquires,__releases \
  1324.         -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \
  1325.         --extra=+f --c-kinds=+px \
  1326.         --regex-asm='/ENTRY\(([^)]*)\).*/\1/'; \
  1327.         $(all-kconfigs) | xargs $1 -a \
  1328.         --langdef=kconfig \
  1329.         --language-force=kconfig \
  1330.         --regex-kconfig='/^[[:blank:]]*config[[:blank:]]+([[:alnum:]_]+)/\1/'; \
  1331.         $(all-defconfigs) | xargs -r $1 -a \
  1332.         --langdef=dotconfig \
  1333.         --language-force=dotconfig \
  1334.         --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'; \
  1335.     elif $1 --version 2>&1 | grep -iq emacs; then \
  1336.         $(all-sources) | xargs $1 -a; \
  1337.         $(all-kconfigs) | xargs $1 -a \
  1338.         --regex='/^[ \t]*config[ \t]+\([a-zA-Z0-9_]+\)/\1/'; \
  1339.         $(all-defconfigs) | xargs -r $1 -a \
  1340.         --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; \
  1341.     else \
  1342.         $(all-sources) | xargs $1 -a; \
  1343.     fi
  1344. endef
  1345.  
  1346. quiet_cmd_cscope-file = FILELST cscope.files
  1347.       cmd_cscope-file = (echo \-k; echo \-q; $(all-sources)) > cscope.files
  1348.  
  1349. quiet_cmd_cscope = MAKE    cscope.out
  1350.       cmd_cscope = cscope -b
  1351.  
  1352. cscope: FORCE
  1353.     $(call cmd,cscope-file)
  1354.     $(call cmd,cscope)
  1355.  
  1356. quiet_cmd_TAGS = MAKE   $@
  1357. define cmd_TAGS
  1358.     rm -f $@; \
  1359.     $(call xtags,etags)
  1360. endef
  1361.  
  1362. TAGS: FORCE
  1363.     $(call cmd,TAGS)
  1364.  
  1365. quiet_cmd_tags = MAKE   $@
  1366. define cmd_tags
  1367.     rm -f $@; \
  1368.     $(call xtags,ctags)
  1369. endef
  1370.  
  1371. tags: FORCE
  1372.     $(call cmd,tags)
  1373.  
  1374.  
  1375. # Scripts to check various things for consistency
  1376. # ---------------------------------------------------------------------------
  1377.  
  1378. includecheck:
  1379.     find * $(RCS_FIND_IGNORE) \
  1380.         -name '*.[hcS]' -type f -print | sort \
  1381.         | xargs $(PERL) -w scripts/checkincludes.pl
  1382.  
  1383. versioncheck:
  1384.     find * $(RCS_FIND_IGNORE) \
  1385.         -name '*.[hcS]' -type f -print | sort \
  1386.         | xargs $(PERL) -w scripts/checkversion.pl
  1387.  
  1388. namespacecheck:
  1389.     $(PERL) $(srctree)/scripts/namespace.pl
  1390.  
  1391. endif #ifeq ($(config-targets),1)
  1392. endif #ifeq ($(mixed-targets),1)
  1393.  
  1394. PHONY += checkstack kernelrelease kernelversion
  1395.  
  1396. # UML needs a little special treatment here.  It wants to use the host
  1397. # toolchain, so needs $(SUBARCH) passed to checkstack.pl.  Everyone
  1398. # else wants $(ARCH), including people doing cross-builds, which means
  1399. # that $(SUBARCH) doesn't work here.
  1400. ifeq ($(ARCH), um)
  1401. CHECKSTACK_ARCH := $(SUBARCH)
  1402. else
  1403. CHECKSTACK_ARCH := $(ARCH)
  1404. endif
  1405. checkstack:
  1406.     $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
  1407.     $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
  1408.  
  1409. kernelrelease:
  1410.     $(if $(wildcard include/config/kernel.release), $(Q)echo $(KERNELRELEASE), \
  1411.     $(error kernelrelease not valid - run 'make prepare' to update it))
  1412. kernelversion:
  1413.     @echo $(KERNELVERSION)
  1414.  
  1415. # Single targets
  1416. # ---------------------------------------------------------------------------
  1417. # Single targets are compatible with:
  1418. # - build whith mixed source and output
  1419. # - build with separate output dir 'make O=...'
  1420. # - external modules
  1421. #
  1422. #  target-dir => where to store outputfile
  1423. #  build-dir  => directory in kernel source tree to use
  1424.  
  1425. ifeq ($(KBUILD_EXTMOD),)
  1426.         build-dir  = $(patsubst %/,%,$(dir $@))
  1427.         target-dir = $(dir $@)
  1428. else
  1429.         zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
  1430.         build-dir  = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
  1431.         target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
  1432. endif
  1433.  
  1434. %.s: %.c prepare scripts FORCE
  1435.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1436. %.i: %.c prepare scripts FORCE
  1437.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1438. %.o: %.c prepare scripts FORCE
  1439.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1440. %.lst: %.c prepare scripts FORCE
  1441.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1442. %.s: %.S prepare scripts FORCE
  1443.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1444. %.o: %.S prepare scripts FORCE
  1445.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1446. %.symtypes: %.c prepare scripts FORCE
  1447.     $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
  1448.  
  1449. # Modules
  1450. / %/: prepare scripts FORCE
  1451.     $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
  1452.     $(build)=$(build-dir)
  1453. %.ko: prepare scripts FORCE
  1454.     $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \
  1455.     $(build)=$(build-dir) $(@:.ko=.o)
  1456.     $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
  1457.  
  1458. # FIXME Should go into a make.lib or something 
  1459. # ===========================================================================
  1460.  
  1461. quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
  1462.       cmd_rmdirs = rm -rf $(rm-dirs)
  1463.  
  1464. quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
  1465.       cmd_rmfiles = rm -f $(rm-files)
  1466.  
  1467.  
  1468. a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
  1469.       $(NOSTDINC_FLAGS) $(CPPFLAGS) \
  1470.       $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
  1471.  
  1472. quiet_cmd_as_o_S = AS      $@
  1473. cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
  1474.  
  1475. # read all saved command lines
  1476.  
  1477. targets := $(wildcard $(sort $(targets)))
  1478. cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  1479.  
  1480. ifneq ($(cmd_files),)
  1481.   $(cmd_files): ;    # Do not try to update included dependency files
  1482.   include $(cmd_files)
  1483. endif
  1484.  
  1485. # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
  1486. # Usage:
  1487. # $(Q)$(MAKE) $(clean)=dir
  1488. clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
  1489.  
  1490. endif    # skip-makefile
  1491.  
  1492. PHONY += FORCE
  1493. FORCE:
  1494.  
  1495. # Cancel implicit rules on top Makefile, `-rR' will apply to sub-makes.
  1496. Makefile: ;
  1497.  
  1498. # Declare the contents of the .PHONY variable as phony.  We keep that
  1499. # information in a variable se we can use it in if_changed and friends.
  1500. .PHONY: $(PHONY)
  1501.